package com.example.algorithms.sorting;

public class SelectionSort {
	
	public static void main(String... args){
		int[] input = {10, 49, 1, 2, 5, 100, 78, 3, 11};
		sort(input, true);
		
		for (Integer item : input){
			System.out.print(item + " ");
		}
	}
	
	public static void sort(int[] input, boolean asc){
		int maxValue = 0;
		
		if ((input != null) && (input.length > 0)){
			
			for (int x = 0; x < input.length - 1; x++){
				
				for (int y = x; y < input.length -1; y++){
					
					if (asc ? input[x] > input[y + 1] : input[x] < input[y + 1]){
						maxValue = input[x];
						input[x] = input[y + 1];
						input[y + 1] = maxValue;
					}
				}
			}
		}
	}
}